package com.dalin.platform.autocode.action;

import java.util.ArrayList;
import java.util.List;

import com.dalin.common.utils.StringUtils;
import com.dalin.framework.action.StrutsTwoAction;
import com.dalin.platform.autocode.condition.GlbDicItemRepositoryCondition;
import com.dalin.platform.autocode.service.AutocodeService;
import com.dalin.platform.autocode.vo.GlbDicItemRepositoryTreeVo;
import com.dalin.platform.glb.model.GlbDicItemRepositoryEntity;
import com.dalin.platform.loa.LoaConst;
/*****************************************************************************
 * @content: 类信息                                                   *
 * @author : 那建林                                                                                                                                 *
 * @crtDate: 2010-06-07                                                     *
 * @modDate: 2010-06-07                                                     *
 * @version: 1.00                                                           *
 ****************************************************************************/
public class GlbDicItemReposQueryAction extends StrutsTwoAction{
    private AutocodeService autocodeService; // 
    private Long typeId;
    private Integer parentId;
    
    public String execute() throws Exception {
        super.printInfo("", "===== this action begin");
        try {
        	List<GlbDicItemRepositoryTreeVo> rtnList = null;
            rtnList = new ArrayList<GlbDicItemRepositoryTreeVo>();
            GlbDicItemRepositoryCondition cond = new GlbDicItemRepositoryCondition();
            cond.setTypeId(typeId);
            cond.setParentId(getParentId());
            List<GlbDicItemRepositoryEntity> entyList = autocodeService
            		.queryListByCond(cond.prepareParams());
            GlbDicItemRepositoryTreeVo vo = null;
            for (GlbDicItemRepositoryEntity enty : entyList) {
            	vo = new GlbDicItemRepositoryTreeVo();
            	vo.setId(enty.getItemId()+"");
            	vo.setHref(enty.getItemCode() + "");
            	vo.setText(enty.getItemName());
            	vo.setParentId(enty.getParentItemCode()+"");
            	vo.setRemark(enty.getRemark());
            	vo.setQtip("主&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;键:&nbsp;" + vo.getId()
            			   + "<br>细目代码:&nbsp;" + vo.getHref()
            			   + "<br>细目名称:&nbsp;" + vo.getText()
            			   + "<br>备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注:&nbsp;" + StringUtils.toString(vo.getRemark()));
            	
            	cond.setTypeId(typeId);
                cond.setParentId(enty.getItemCode());
            	List childrenList = autocodeService
            			.queryListByCond(cond.prepareParams());
            	if (StringUtils.isBlank(childrenList)) {
            		vo.setLeaf(true);
            	}
            	rtnList.add(vo);
            }
            setResContent(rtnList);
        } catch (Exception e) {
        	e.printStackTrace();
        }
        super.printInfo("", "===== this action end");
        return null;

    }

    public AutocodeService getAutocodeService() {
		return autocodeService;
	}
	public void setAutocodeService(AutocodeService autocodeService) {
		this.autocodeService = autocodeService;
	}

	public Integer getParentId() {
		return  parentId == null ? LoaConst.BASE_PARENT_ID : parentId;
	}

	public void setParentId(Integer parentId) {
		this.parentId = parentId;
	}

	public Long getTypeId() {
		return typeId;
	}

	public void setTypeId(Long typeId) {
		this.typeId = typeId;
	}
}
